找传奇、传世资源到传世资源站!

C# 定时器(倒计时)示例源码

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

设定计时时间,时间到后音箱发出声音,再次循环,小计时器生产岗位做节拍器提的需求
from clipboard
from clipboardusing System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace WindowsFormsTime{ public partial class Form1 : Form { public int A_stcnt; public int A_time; public Form1() { InitializeComponent(); } private void timer1_Tick(object sender, EventArgs e) { A_stcnt = A_stcnt-1; if (A_stcnt <= 0) { A_stcnt = A_time; System.Media.SoundPlayer player = new System.Media.SoundPlayer(Properties.Resources._123); // player.SoundLocation = @"D:\kf-dzh\3.C#App\WindowsFormsTime\WindowsFormsTime\sound\123.wav"; player.LoadAsync(); player.Play(); //system.Media.SystemSounds.Asterisk.Play(); } lb_dsp.Text = A_stcnt.ToString(); } private void Form1_Load(object sender, EventArgs e) { A_time= Convert.ToInt32(tb_begin.Text); A_stcnt = A_time; lb_dsp.Text = A_time.ToString(); tb_begin.Enabled = false; } private void button1_Click(object sender, EventArgs e) { try { A_time = Convert.ToInt32(tb_begin.Text); A_stcnt = A_time; } catch { MessageBox.Show( "请输入数字! ");  return; } tb_begin.Enabled = false; } private void label2_Click(object sender, EventArgs e) { if(tb_begin.Enabled == true) { tb_begin.Enabled = false; } else if (tb_begin.Enabled == false) { tb_begin.Enabled = true; } } }}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复